<template>
<div id="welcome">
  <p>program starting </p>
  {{time}}
  {{yes}}

  <textarea v-model="jsdata" rows="10" cols="35"></textarea>
  <button id="rundata" @click="rundata()">RUN</button>
  <iframe id="iframe1"></iframe>


</div>
</template>

<script>
export default {
  name: "Welcome",
  components: {

  },
  data() {
    return {
      time: 0,
      yes: " ",
      jsdata:"",
      output:"",
    }
  },

  methods: {
    countDown() {
      let THIS = this;
      THIS.time++;
    },
    rundata() {
      //获取输入框内的数据
      let text = this.jsdata;
      // 先清空iframe
      var iframe = document.getElementById("iframe1").contentWindow.document.body.innerText = "";
      //将输入框内的数据传给iframe
      iframe = document.getElementById('iframe1').contentDocument.write(text);
    }
  },
  mounted() {
    let THIS = this;
    // 把time改为5
    THIS.time = 5;
    // 设定一个定时器，每一秒调用一次coundDown方法，time-1
    setInterval(THIS.countDown, 1000);
  },
  watch: {
    //   监听time的值
    time: function (newVal) {
      if (newVal <= 0) {
        this.yes='dadsa';
            this.$router.push("/problems_list");
      }
    }
  },
}
</script>

<style>

</style>